package org.openmore.consumer.service.feign;

import io.swagger.annotations.ApiParam;
import org.openmore.consumer.dto.common.BaseResponse;
import org.openmore.consumer.dto.common.ForeignResourceDto;
import org.openmore.consumer.entity.enums.ResourceForeignType;
import org.openmore.consumer.service.feignImpl.ResourceServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@Service
@FeignClient(value = "openmore-storage", fallbackFactory = ResourceServiceImpl.class)
public interface ForeignResourceService {


    @RequestMapping(method = RequestMethod.GET, value = "/api/foreignResource/query")
    public BaseResponse selectAllByPage(@RequestParam(required = false) @ApiParam(value = "资源ID") String resourceId,
                                        @RequestParam(required = false) @ApiParam(value = "关联ID") String foreignId,
                                        @RequestParam(required = false) @ApiParam(value = "使用类型") ResourceForeignType foreignType,
                                        @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "分页第几页") Integer pageNum,
                                        @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页多少记录") Integer pageSize);


    @RequestMapping(method = RequestMethod.GET, value = "/api/foreignResource/{id}")
    public BaseResponse getForeignResourceById(@PathVariable @ApiParam(required = true, value = "id") String id);


    @RequestMapping(method = RequestMethod.PUT, value = "/api/foreignResource")
    public BaseResponse updateForeignResource(@RequestBody @ApiParam(value = "新信息", required = true) ForeignResourceDto foreignResource);


    @RequestMapping(method = RequestMethod.POST, value = "/api/foreignResource", consumes = {APPLICATION_JSON_UTF8_VALUE})
    public BaseResponse insertForeignResource(@RequestBody @ApiParam(value = "创建", required = true) ForeignResourceDto foreignResource);


    @RequestMapping(method = RequestMethod.POST, value = "/api/foreignResource/list", consumes = {APPLICATION_JSON_UTF8_VALUE})
    public BaseResponse insertForeignResources(@RequestParam @ApiParam(value = "关联课程/专题ID", required = true) String foreignId,
                                               @RequestParam @ApiParam(value = "资源ID集合", required = true) String[] resourceIds,
                                               @RequestParam(required = false) @ApiParam(value = "使用类型")ResourceForeignType resourceForeignType,
                                               @RequestParam(required = false) @ApiParam(value = "需要和resourceIds集合对应", required = true) String[] params);


    @RequestMapping(method = RequestMethod.DELETE, value = "/api/foreignResource/{id}")
    public BaseResponse deleteForeignResourceById(@PathVariable @ApiParam(value = "id", required = true) String id);


    @RequestMapping(method = RequestMethod.DELETE, value = "/api/foreignResource/foreignId/{fId}/resource/{rId}")
    public BaseResponse deleteForeignResource(@PathVariable @ApiParam(value = "外键id", required = true) String fId,
                                              @PathVariable @ApiParam(value = "资源id", required = true) String rId);
}
